/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Controlador;

import Modelo.ENT_Feria;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Isaac Paliza <anndysaac@hotmail.com>
 */
public class CTRL_AsignarPersonalFeria {
    private static final ConnectionJDBC connectionJDBC = new ConnectionJDBC();
    private static final Statement statement = connectionJDBC.createStatement();
    public static String Mensaje;

    public static List CargarListaFeria() throws SQLException {
        ArrayList<ENT_Feria> ListaATrabajadores = new ArrayList();
        String sql = "SELECT idFeria, Nombre "
                + "FROM t_feria ";
        ResultSet recordingResults
                = ConnectionJDBC.executeQuery(statement, sql);
        while (recordingResults.next()) {
            String idFeriaAux = recordingResults.getString(1);
            if (recordingResults.wasNull()) {
                idFeriaAux = "";
            }
            String NombreAux = recordingResults.getString(2);
            if (recordingResults.wasNull()) {
                NombreAux = "";
            }
            ListaATrabajadores.add(new ENT_Feria(idFeriaAux, NombreAux));
        }
        return ListaATrabajadores;
    }

    public static List CosultarFeria(String idFeria) throws SQLException {
        ArrayList<ENT_Feria> ListaATrabajadores = new ArrayList();
        String sql = "SELECT F.idFeria, F.Nombre, F.fechaInicio, F.fechaFin, COUNT( * ), F.ubicacion "
                + "FROM t_feria AS F "
                + "INNER JOIN t_trabajador_has_t_feria AS X ON F.idFeria = X.idFeria "
                + "WHERE F.idFeria ="+idFeria+" "
                + "AND X.situacion =  'Activo' ";
        ResultSet recordingResults
                = ConnectionJDBC.executeQuery(statement, sql);
        while (recordingResults.next()) {
            String idFeriaAux = recordingResults.getString(1);
            if (recordingResults.wasNull()) {
                idFeriaAux = "";
            }
            String NombreAux = recordingResults.getString(2);
            if (recordingResults.wasNull()) {
                NombreAux = "";
            }
            String fechaInicioAux = recordingResults.getString(3);
            if (recordingResults.wasNull()) {
                fechaInicioAux = "";
            }
            String fechaFinAux = recordingResults.getString(4);
            if (recordingResults.wasNull()) {
                fechaFinAux = "";
            }
            String nTrabajadoresAux = recordingResults.getString(5);
            if (recordingResults.wasNull()) {
                nTrabajadoresAux = "0";
            }
            String UbicacionAux = recordingResults.getString(6);
            if (recordingResults.wasNull()) {
                UbicacionAux = "";
            }
            ListaATrabajadores.add(new ENT_Feria(idFeriaAux, NombreAux, fechaInicioAux, fechaFinAux, nTrabajadoresAux, UbicacionAux));
        }
        return ListaATrabajadores;
    }
    
}
